package com.wwj.study.proxy.study;

import com.wwj.study.proxy.Person;

import java.io.IOException;
import java.lang.reflect.Method;

/**
 * Created by lenovo on 2018/11/18.
 */
public class StudyMeipo implements WInvocationHandler {
    private Person person;

    public Object getInstance(Person person) throws Exception {
        this.person=person;

        Class<?> clazz = person.getClass();

        Object object= WProxy.newProxyInstance(new WClassLoader(),clazz.getInterfaces(),this);

        return object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("开始物色");
        //执行被代理对象方法
        //传入被代理对象，参数
        method.invoke(this.person,args);
        System.out.println("找到了");
        return null;
    }
}
